<template>
  <div>
    <el-table :data="goods" border style="width: 100%">
      <el-table-column prop="id" label="商品编号"> </el-table-column>
      <el-table-column prop="goodsname" label="商品名称" > </el-table-column>
      <el-table-column prop="price" label="商品价格"> </el-table-column>
      <el-table-column prop="market_price" label="市场价格"> </el-table-column>
      <el-table-column prop="img" label="图片">
        <template slot-scope="scoped">
          <div>
            <img :src="$pre+scoped.row.img" alt="">
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="isnew" label="是否新品">
        <template slot-scope="scoped">
          <div>
            <el-button v-if="scoped.row.isnew==1">是</el-button>
            <el-button v-else>否</el-button>
          </div>
          </template>
      </el-table-column>
      <el-table-column prop="ishot" label="是否热卖">
         <template slot-scope="scoped">
          <div>
            <el-button v-if="scoped.row.ishot==1">是</el-button>
            <el-button v-else>否</el-button>
          </div>
          </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
         <template slot-scope="scoped">
          <div>
            <el-button type="success" v-if="scoped.row.status==1">启用</el-button>
            <el-button type="info" v-else>禁止</el-button>
          </div>
          </template>
      </el-table-column>
      <el-table-column  label="操作">
         <template slot-scope="scoped">
          <div>
            <el-button type="success" @click="update(scoped.row.id)">编辑</el-button>
            <v-del @del="del(scoped.row.id)">删除</v-del>
          </div>
          </template>
      </el-table-column>
    </el-table>
    <el-pagination
  background
  layout="prev, pager, next"
  :total="totals" :page-size="sizes"
  @current-change="changePage">
</el-pagination>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { goodsdelete} from "../../../request/api.js";
import { successAlert, warningAlert } from "../../../utils/alert.js";
export default {
  data() {
    return {
        
    };
  },
  computed: {
    ...mapGetters({
     goods:"goods/list",
     totals:"goods/total",
     sizes:"goods/size"
    }),
  },

  methods: {
    ...mapActions({
       goodslist:"goods/asyncChangeList",
       totallist:"goods/asyncChangeTotal",
       pagelist:"goods/asyncChangePage"
    }),
    //删除
del(id){
goodsdelete({id:id}).then(res=>{
  if(res.data.code==200){
    successAlert(res.data.msg)
    this.goodslist()
    this. totallist()
  }else{
    warningAlert(res.data.msg)
  }
})
},
    //点击编辑
update(id){
  this.$emit('update',id);
  
},
    //当前页码数
changePage(e){
  this.pagelist(e)
}
    //页面进来请求列表数据
  },
  mounted(){
   
    this.totallist()
    this.pagelist(1)
  }
};
</script>

<style>
img{
  width: 100px;
  height: 100px;
}
</style>